home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / raymovi2.arc / FILE.C < prev    next >
C/C++ Source or Header  |  1988-12-21  |  2KB  |  100 lines

  1. #include "\include\gemdefs.h"
  2. #include "\include\osbind.h"
  3. #include "rtd.h"
  4. int debug;
  5.  
  6. #define GRMODE   0          /* graphics mode 0 (320x200) */
  7. #define FSIZE  32034        /* size of DEGAS save-file */
  8. int    vs_handle;        /* virtual screen (workstation) handle */
  9. int *clut_fetch();
  10. int read_pal[16];
  11.  
  12. /* the first FSIZE bytes of the file is DEGAS */
  13.  
  14. /* save screen data to disk in DEGAS-like format */
  15.  
  16. f_write(fn)
  17. char *fn;
  18. {
  19.    char *scrnp;
  20.    int fd, n;
  21.    short gmode[1];
  22.  
  23.    if (fn == 0)
  24.     return (-1);
  25.    scrnp = (char *)Physbase() ;  /* get pointer to display frame */
  26.    *gmode = GRMODE ;
  27.  
  28.    if ((fd = creatb(fn, 0755)) < 0) 
  29.     return(-1);
  30.  
  31.    n = write(fd, gmode, 2);        /* write graphics mode */
  32.    n += write(fd, clut_fetch() /*palet(ind)*/, 32);    /* write palette */
  33.    n += write(fd, scrnp, 32000);    /* write screen data */
  34.    close(fd);
  35.  
  36.    if (n != FSIZE)
  37.    {  unlink(fn);
  38.       panic("Not enough space on disk to write file\n(need 32K)");
  39.    }
  40.    return(0) ;
  41. }
  42.  
  43. /* read file (DEGAS format) */
  44. int f_read(fn, buf)
  45. char *fn, *buf;
  46. {
  47.    char *scrnp;
  48.    int fd, n;
  49.    short gmode[1];
  50.  
  51.    if (fn == 0)
  52.     return (-1);
  53.    if ((fd = openb(fn, 0)) < 0) 
  54.     return(-1);
  55.  
  56.    n = read(fd, gmode, 2);        /* read graphics mode */
  57.    n += read(fd, &read_pal, 32);    /* read palette */
  58.    n += read(fd, (buf? buf: (char *)Physbase()), 32000);
  59.    close(fd);                /* read screen data */
  60.    
  61.    if (n != FSIZE)
  62.     return(-2);            /* file read error: file too short */
  63.    clut_put(&read_pal);
  64.  
  65.  
  66.    return(0);
  67. }
  68.  
  69. int scramble[16] = {0, 2, 3, 6, 4, 7, 5, 8, 9, 10, 11, 14, 12, 15, 13, 1};
  70.  
  71. int *clut_fetch()
  72. {    int *p = read_pal, i;
  73.     int rgb[3], red, green, blue;
  74.  
  75.     for (i=0; i<16; i++)
  76.     {    vq_color(vs_handle, scramble[i], 0, rgb);
  77.         red   = rgb[0] / 125;    
  78.         green = rgb[1] / 125;
  79.         blue  = rgb[2] / 125;
  80.         if (debug)
  81.             printf("cF(%d>%d): %d %d %d ->%d %d %d\n",i,scramble[i],
  82.                 rgb[0], rgb[1], rgb[2], red, green, blue);
  83.         *p++ = (red*0x100 + green*0x10 + blue);
  84.     }
  85.     return(read_pal);
  86. }
  87.  
  88. #define clr(r) 1000*(2*(r)+1)/16;
  89.  
  90. clut_put(p)
  91. int *p;
  92. {    int i;
  93.     int rgb[3], red, green, blue;
  94.     for (i=0; i<16; i++, p++)
  95.     {    rgb[0] = clr( *p >>8 & 0xf);    /* red */
  96.         rgb[1] = clr( *p >>4 & 0xf);    /* green */
  97.         rgb[2] = clr( *p & 0xf);    /* blue */
  98.         vs_color(vs_handle, scramble[i], rgb);
  99. }    }
  100.